package net.sf.jOpinionPoll.miscellaneous;

import java.io.IOException;

import org.apache.log4j.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class JOpinionPollFilter implements Filter {
	private static final Logger m_Logger = Logger.getLogger(JOpinionPollFilter.class);
    
    public JOpinionPollFilter() {
    }
    
	public void destroy() {
		m_Logger.info("JOpinionPoll filter finalizado");
    }
    
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
        throws IOException, ServletException {
    	
    	if (request instanceof HttpServletRequest) {
    		HttpServletRequest r = (HttpServletRequest)request;
    		System.out.println("URL solicitada: " + r.getScheme() + "://" + r.getServerName() + ":" + r.getServerPort() + r.getRequestURI() + ( r.getQueryString() != null ? "?" + r.getQueryString() : ""));
    	}
        
        chain.doFilter(request, response);
    }
    
    public void init(FilterConfig filterConfig) {
        m_Logger.info("JOpinionPoll filter inicializado");
    }
}